
/**
 * 合并多个 reducer 返回一个合并后的 reducer
 */
function combineReducers(reducers) {
  return function(state = {}, action) {
    let nextState = {}
    for (const key in reducers) {
      let prevStateForKey = state[key] // 获取当前(老) key 的 state 状态
      let reducerForKey = reducers[key] // 获取当前 key 的 reducer 处理器函数
      nextState[key] = reducerForKey(prevStateForKey, action)
    }
    return nextState
  }
}

export default combineReducers
